package org.example.dubbo.pro.service;

import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.rpc.RpcContext;
import org.example.dubbo.api.entity.User;
import org.example.dubbo.api.service.UserService;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Random;
import java.util.UUID;

@Slf4j
@DubboService
@Component
public class UserServiceImpl implements UserService {
    @Override
    public User queryUserInfo(long userId) {
        log.info("request from consumer:{}",RpcContext.getServiceContext().getRemoteAddress());
        log.info("reponse from producer:{}", RpcContext.getServerContext().getLocalAddress());
        User userEntity =new User();
        Random random = new Random();
        userEntity.setId(random.nextLong()+1L);
        userEntity.setGuid(UUID.randomUUID().toString());
        userEntity.setName("金信"+random.nextInt(1000));
        userEntity.setAge(random.nextInt(100));
        userEntity.setUserDesc("上海疫情管控区");
        userEntity.setCreateTime(new Date());
        log.error("user:"+userEntity);
        return userEntity;
    }
}
